This reverts commit f4e1eaa3. The patch was originally reverted because it uncovered an issue that has now been fixed in 0ef8ca6d.