Refactor out conditional tree