recursive, more compact code