Cleaned up some module cache misbehaviors. Fixes #535