Some tidy up. Externalise more JS. Used better names for some HTML ids.