Added appropriate fclose() statements.