format JS code and chained the functions