cleanup, comments and unit tests