Tidied up and separated server and client js