refactor: reduce nesting