Fixed class cast exception. It was a rather stupid bug.

I actually tested it this time. I'll try and actually test things now.