Added some finally blocks removing code duplication.