Fix code output, also output cost.