fixed #15 - reentrancy with two loops