cleanup and some unit tests