This duplicates a lot of the code in exercise_handler in main.views - should be consolidated at some point.