Fixed next and previous function