guard against bad encoding in queries
stop crashing on a terminal too small