Tidy up controller. Update to new pg lib.

Long SQL strings have now been moved to external files that are read on startup.

DB connection method has been improved as per node-postgres wiki docs.

Frontend now only makes one request on startup if no hash is present.