code reorg, fixed sem check