Refactor thread sleeping (time delay) API