Pass rest server address to JS

Plus code tidying
JavaScript tidy