Several bug fixes, notably for the caching