Refactoring explicit type casting