Code quality refactor