Fix compile and logic errors.