reorganized and commented code, changed randomizer