added extra checking to avoid devicde by zero php error Fixes #41