Please factorize all those if into one single if (or at least group them in two if if you prefer) as you break in all cases.