Correctly dealing with ENDIF and closing <file>