performance improvement

Trying to reduce dom access by caching.