cost function modified, plot added