A few code cleanup refactors