Fix a couple of bugs and compile warnings.