remove exit calls in preference to raise exceptions
add sleep to avoid busy loop