UC-53 Reduce nesting and make logic easier to follow