added logic for page scroll and switching pages