reverted to original math and found bug in switch code. fixed