Fix issues with tree writer for modules and default export

Fixes #439