updated code to use the prev and next buttons