Refactor to minify nesting