improved js code according to jsLint