removed unused code, fixed some variable references