Use -o instead of -g for debug-file
Wraps monitor with category.

Also, move codes around so that the wrapping for the monitor and batch
options get the same scope.
Consolidate monitoring in a single function