fclose earlier, fixed identation