Reduce code nesting