improve javascript snippets