debugging almost finished,some bug in logic