Cleaned up JavaScript and moved to separate file

Cleaned up JavaScript and moved to a different file, plus geolocation
improvements