refactoring and moar tests