next/prev commands

Refactored next/prev commands. @lydell would you like to review before merging?