reworked to function as a daemon