Library: Refactoring alloc/dealloc functions. Normally the token should be passed so extra validation can be made