Move the scrollback navigation code to a better place