code cleanup and unit tests