almost working implementation