Improve reliability by adding flags for when input starts and stops and using counters to determine if mapping or reducing is taking place.