can't divide by 0, and some other fixes to random