Added @ended check in @next and @prev