Only 2 changes in this block of code: 1) the if is split into 2 if and 2) this line (i.e. FromTimestamp) is moved from outside the outer if to here.