Fixed segmentation fault related to output