Tidied up JS & PHP code