Minor js tidying and speed improvements