Refactor, extracting code into function.