Fix to make config parsing work on py3k too.
Also wrapped it in a function to prevent variable leaking.