added code to check for length of time in states and log if too long