LGTM. BTW, can we refactor this ? the whole scheme of nested conditional looks ugly to me ... possibly we could use a combination of guard clause and switch/case.