Refactor. Thanks @Flambino for suggestions!

See code review @
http://codereview.stackexchange.com/questions/44520/activerecord-extension-to-find-next-previous-records-in-one-query/44719#44719