Some minor changes and additional logging added.