Warning fixes v3

This fixes a series of warnings across the system. Please perform a careful code review, then merge at will.