first working version of the whole allocating process @dahernan, @colinbruce, @danielatjustice