simplify code: always be recursive
better error handling