updated for non blocking version