refactor and organize JS code for monitors UI