added debug, fixed a bug