fix condition of output sum