have way done with slower algorithm