adding regression tests for "getting parents context" and also for double loop
case. Also refactored a bit pull request #91 . Also closes #90 and #87