Restructures javascript