Refactor monitor logic