Algorithm improvements

tweaks to get better results