fixing possible division by zero exception