Fixing next/previous functionality