cleanup, enhancements and unit tests