Issue #144: refactoring to reuse some code: moving code to editor where it can be reused