Fix semantic issues flagged by clang