Tidied up JS / better comments