Here's a basic patch that does the bare minimum, and seems to work.