Constructed majority of the main code.