implemented fragment caching. removed a bunch of redundant code