Make functions more general and add Debugf etc.