Fixed bug and removed unused variable