fix class-cast exception and added beginnings of DBRef inference mechanism