Better implementation of major mode.