update working code, still slow version