Refactor code and add some editor functions