working version of blocking buffer