Implementation with all tests passed