refactor code in separated files, and enhance the use of requireJS to prevent bad file loading order