In the compiled JS, restored environments properly after a function call. Also took care of various easy TODOs.