tweaks to algorithm