optimized. Made a few object variables local