change the logic and correct error