function caching

+ dead code removed