some fixes for reentrancy issues