Improve wait and quit process.

Refactor logic from backend to the vpnprocess.