Added division by zero check. hopefully