A more generic, still leeking implementation.