UPDATE javascript code tidy for debug to work