Sometimes a litte sleep() is all you need - that seemed to stop the program from crashing