rewrote condition variables