More checks and balances on files and pointers.
Merge pull request #47 from rudigens/roipac

More checks and balances on files and pointers.