Total rewrite, now runs as a daemon for use with readsocket