Refactors Element#next and #previous methods and removes duplication.