first version almost working