add chosen plugin and refactore some code