Cleanup and improved test coverage