rewrote code

BixbyC wrote this code, but we added the branch in the wrong place, so
this code is now being added back in.