refactored, moved allocation logic into domain