rejiggered code and writing slightly to get module inclusions right, needs verification