might need to merge
added some division by zero checks