Added protection for y=0 and ey=0 for not weighted calculation