Added some logging and exception throwing.