Started to add full daemon code. The basics are mostly working.