refactor type conversion hacks