Reorganized code in javascript file.