improved caching and cleaned up jquery