optimized some javascript code