Integrated code, added figure generation