several cosmetic changes, minor changes to algorythm