more cleanup, add unit test