Bug fix, move generated files out and restore input even when the program hangs