Add Abe's code from commit 5ecea2f