Significant refactoring; explicit reference-counting in many places; module handling.