refactoring to make scheme a bit more resuable