Reworked 'add' foreign function