Fix compiler warnings (including a serious bug)