tweaked code cfg to allow negative numbers