Code refactored, test completed