Split things to be more modular and not having to rewrite common code for the gui/cmd version.