Re-wrote with-statements to use try-finally (Python 2.6 on CIT).