Added comments in JS script + reorganizing it a bit