Refactor: variable names and function extract