code refactoring - typechecks