Add logging and a little more checking
Add some more logging.
Use the registry settings rather than the environment.