Fix various bugs.