Consider edge cases in when finding next and previous positions