all tests passing, working implementation 1