Code cleanup and test coverage increase