Wrote almost all the code