A lot of minor code improvements for more uniformity and less duplication.