adding unit tests and fixing things along the way