Here's an updated version of my patch, that uses a list of functions: