Clean up mode logic to facilitate merge.