Move the scroll-to-bottom code to the correct place