refactored codemirror code