Added conditions to the next/prev links