previous and next functions now work