need to add support for references etc here too