Start refactor larger commands into plugins.

Also do some code cleanup.