removed the break when error gets low enough as it doesn't make much sense
reshufled the code a little, added a regenerate function. It\'s suboptimal, but who cares