New version with debugging