Remove reliance on globals

Also, tidy up markup/css and some code styling