Additional cleanup and more unit tests