Removed unused local variables. Fixed bug