Fix bugs and GCC warnings.