almost working, except bug