Writing scroll functions for smoother experience