Without going to far into it perhaps inserting a brief sleep statement would solve the issue.