cleanup and add tests