Towards a theory of macroinvertebrate community structure in stream ecosystems