Fixing null reference when closing transactions