Add basic support for handling forward references in gradients (only handles one level of indirection). Fixes issue #81.