Corect simple errors and modiff textbuddy determinecommandtype method

Fix bugs of duplicate output and add sort and search into above method.