I'd refactor this to avoid the 2 very similar branches.