Added code and tests for allocate()