modules: Use a better scheme for refcounting