chainable functions and externalized caching variables + some minor optimizations