Scheduler code cleanup

- bug fixes
- setup signal handlers
- endless scheduler cycle
- setup lock file