implement recursion & raise error if failed