nicer code, more dbg/checks