added check to avoid division by zero.