Cleanup before adding external grader

This is a minor cleanup of module_render, and xmodule.handle_ajax related functions. It does not add any new features.

It will be followed up by two more PRs for the external grader libraries that replace xqueue. This PR is separate to reduce the amount of noise in the following PRs.