implemented exit flag system for monitor thread