[DELTA-1452] refactored to reduce nesting

@Deravel