Thread safety cleanup

Make return values of a couple functions be
pointers to const instead of just pointers.
Eliminates some potential thread safety problems
reported by the clang static code analyzer.