Refactor and code coverage