Updated implementation; Passes all but 2 tests