changed prev next to a loop