Use -o instead of -g for debug-file
Consolidate monitoring in a single function