Restructure javascript file