first almost working version