sort js file into a function-based file