code cleanup, unit tests