improves main loop in minimal version

add timeout