Bugfix class cast exception

Minor changes - this bug reported by KBC