major restructure to dynamically allocate resources