Implement most of the functionality in daemon

So, in theory, everything except handling events itself is here, though
this stuff needs some tests first. I updated the specs too. And fixed
build, if anyone cares to have fun with my code.