create prev and next functions