adds try-finally to open so it's actually safe