fix bug and add explanation