Edited for more compatibility with new CodeMirror