fixed bug in foreign pointer wrapper