Main bulk of the work done. Need to work on graph output now