Refactored, but buggy, fix zero divison error