Refactored and improved test coverage