Reindent and move code into document ready