add some tests and a little refactoring