Code quality refactor

Just a brief code cleanup branch. No functional changes.