factored out some common Monitor code to reduce code duplication between
src-opt branches