better logging and exception handling