Pull header generation into separate function; fix test

Pull header generation into a separate function.
Fix formatLoc by exporting separately from declaration
so that function is available locally.