logging and exception handling refactored