Some cleanup and refactors. Mostly for sanity-checks.