cleanup and unit tests