little refactoring and unit tests