Added a divide-by-zero check