code refactored

dependent on this commit:
https://github.com/lwyszomi/commcare-hq/commit/773f13ba1c9a98a70917a3ff8c1925c8e2dab8a0