Performance Improvements

Changed Scoping of variables because some were being declared and
sometimes not used.