restructuring js - complete