reorganized javascript