final code with fixed scrolling problem