Begin to structure main properly

Hide backend implementation.

Also copy code from warden-linux to avoid inappropriate dependency.