Refactor dup and gap methods, add more tests to test them