Refactored and increased test coverage