added debug flag, return value