Massive refactoring of code structure, split unctionality into separate js files for ease of maintenance