added check for div by zero