more logging and deal with errors safely