Bleurgh, rewrite in iterative style to avoid stack overflow :(
Ignore input files