Refactor JS files to help moving forward with graphics. Improve perf.