TODO use iterate loop, rather than recursive