@asmeurer thanks for pointing out the typo. Fixed it.

@skirpichev I have fixed the algorithm. Please have a look.