more code shuffling to reduce complexity