logging and exception handling improved