improve javascript code