 				}
 			}
 			// no event
-			else
+			else {
 				previousState = signalState;
+			}
 		}
 
 	}

void loop() {
	bool responseFlag = false;
	unsigned long existingTime, elapsedTime = 0;
	unsigned char readData[bufferSize];
	digitalWrite(ledPin, LOW);

	// Scan for RFID tags
	Serial.println("Scanning...");
	while(responseFlag == false) {
		MF_SNR();
		delay(200);
		responseFlag = getResponse(readData);
	}

	// RFID tag detected, read block that contains time data (for this machine)
	Serial.println("Card detected.");
	digitalWrite(ledPin, HIGH);
	MF_READ(0x01, machineID);
	delay(50);
	responseFlag = getResponse(readData);

	// Analyze response packet and data
	if(responseFlag == false) {
		soundFeedback(reject);
		Serial.println("Read unsuccessful, please try again.\n");
		delay(500);
	}
	else {
		existingTime = getTime(readData);
		if(readData[8] != classCheck) {
			soundFeedback(reject);
			Serial.println("You are not authorized to use this machine.\n");
		}
		else if(existingTime >= quota) {
			soundFeedback(reject);
			Serial.println("You have reached your quota for this month.\n");
		}

	//Serial.println();

	// 3rd byte of response packet is the STATUS byte, 0x00 means OK
	if (response[statusOffset] == 0x00)
		return true;
	else
		return false;
}
/*
	Reads time data from card and stores it in one 4 byte chunk

	Param: readData - array containing all bytes read from card

	Function: Time is encoded as four 1 byte chunks 0xAA 0xBB 0xCC 0xDD.
			  existingTime is one 4 byte chuck 0x00000000
			  This function XORs the most significant byte with each time byte,
			  and left shifts it 1 byte size every iteration.
			  First iteration: 0x000000AA, Second iteration: 0x0000AABB, etc.

	Returns: existing time from card
*/
unsigned long getTime (unsigned char readData[]) {
	int i = 0;
	unsigned long existingTime = 0;

	for (i = 0; i < numTimeBytes; i++) {
		existingTime = (existingTime << 8) ^ readData[i + timeOffset];
	}

	return existingTime;
