Moved file I/O outside main function.