Working on fixing the cost function