Merge avoid stack overflow

Branch covers #22 , code review and resolves merge conflicts, !