Enable compile warnings, and fix a number of bugs