Some fixes and improvements

Handle multiple generic relations, as well as null ones. This also removed the need to look up the actual foreign object itself (although we still need to look up the content type).