Fixing cast exception