Re-scoped settings, improved exception handling and general code cleanup.