refactor of the monitor.js code