More tests and a little refactor.