better next\prev link code thanks to StackOverflow