replace sleep function to prevent event eating