Tidied up Javascript