Use function form of exec, for Python 3 compatibility

 - Can't use statement form of exec in Python 3
 - Can't use functional form of exec inside a function with a nested
   function with 'free' variables
 - See http://stackoverflow.com/a/9195548