better error handling on init and fixed a division by zero