Extract 'complete_command' method