Fix up logical errors