pass the logger object
fix logic error, and use better error messages