added Allocate macro plus some refactoring