version 3.  almost working