Refactor monitrc to use some local variables