[API] Fixed wrapDevice so there aren't memory leaks