Refactor code for generating codemirror textareas