performance improvement in update loop 

improved the update loop to reduce memory usage and search time.