Solving bug (class cast exception)