created loop and quit event detection