fixing a class cast exception