progress towards MOODS type, allocation everything on the heap and passing around references.  nedd more error checking on the allocations I think