Fixed error in writing outputs.