debugged prev next function