Put module builder/safe warn code into reusable functions.

This way we'll generate less code in cases where there are two or more module imports.