Restructure javascript code in separate files