rearranged blocks to make logging more reliable