Fix deallocation bugs
Prevent double allocation of globals