fixed bugs in next/previous