Tidied up JS