Fix some minor logical bugs.