Removes usages of extract() function

This replaces #6146 and refactors a bit more.