Changed single branch ifs to when, and limited to a single setfcost call