Added functionality for Next and Previous buttons.