WhereClause and Debug fix

Some work to improve where clause logging, also found a code issue while
debugging with isatty()