fixing bugs in reorg code