Revert "Merge pull request #2958 from dimagi/revert" and fix it

https://github.com/dimagi/commcare-hq/pull/2958