Closing function appropriately