improved monitor script