lots of refactoring, implement syslog