refactoring puzzle without typeclasses