[PATCH 0/3] A few cleanups and refactorings, sync w/ upstream