Make type casting code cleaner