It works, except for edge cases