A few code refactors