fixed the error in the logic but there still a bug