Moved most of the command handling into a separate class, for neatness