Fixed potential bug and remove unnecessary code