close opened files if not needed

- add some further small fixes