Clean up code and add auto scroll to top

How is this better formatting?