Clean up code and add auto scroll to top