Fixed a bug and removed an unused variable