add logging and handle exceptions