Add test for adding and removing token from module

Fix implementation of removing token.
Add missing memory cleaning.