Casting Object to something is not safe. Fixes ClassCastException

Thanks to zackp30