updated algorithm among other things. The search is slow though. Needs fix