Added factoryState for factory commands.

Also fixed clear button for terminal view