Code refectored to allow flipping switches and scales.