fixed bug and removed unnecessary code