Fix function edition and add caching to the functions model