Fix bugs shown in compiler warnings