Improved monitor script