This reverts commit 3b052558. This patch got reverted due to an unrelated memory leak that has been fixed.