Fixed terrible misuse of casting.