subprocess loop bug