better javascript code