refactor and fix bug for editor