reorganize order of functions in trials js