create submodule function and cleanup temp buffer.