logging moved into util, with debug option