code cleanup fixed switch on loss

still lots more to do