#86 implement a correct algorithm