fixed locking/waiting semantics and improved output