refactor js codes into one file