Minor refactoring, extract to a function and variable rename