repair next/previous functions