Refactored tests and production code