add sleep function & fix timeout functions