Massive refactor of Trex javascript libraries