Reorganize javascript some