 
 */
 
-void MF_WRITE(unsigned char numBlocks, unsigned char startAddress, unsigned long time) {
-	int i = 0;
+void writeCard(unsigned char numBlocks, unsigned char startAddress, unsigned long time) {
+	int i = 0;
+	int j = 24;
 
 	// prepare data to be written, time is in format 0xAABBCCDD
 	// timeByte is in format { 0xAA, 0xBB, 0xCC, 0xDD }
-	unsigned char timeByte[4];
-	timeByte[3] = time & MSB;
-	timeByte[2] = (time >> 8) & MSB;
-	timeByte[1] = (time >> 16) & MSB;
-	timeByte[0] = (time >> 24) & MSB;
+	unsigned char timeByte[numTimeBytes];
+	for(i = 0; i < numTimeBytes; i++) {
+		timeByte[i] = (time >> j) & MSB;
+		j -= 8;
+	}
 
 	unsigned char A[] = { 0x00, 0x1A, CMD_WRITE, 0x01, numBlocks, startAddress,
-						0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+						keyA[0], keyA[1], keyA[2], keyA[3], keyA[4], keyA[5],
 						0xDD, 0xA1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
 						timeByte[0], timeByte[1], timeByte[2], timeByte[3] };
 	unsigned char BCC = checksum( A, sizeof(A)/sizeof(A[0]) );
 	unsigned char CMD[] = { STX, 0x00, 0x1A, CMD_WRITE, 0x01, numBlocks, startAddress,
-						0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+						keyA[0], keyA[1], keyA[2], keyA[3], keyA[4], keyA[5],
 						0xDD, 0xA1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
 						timeByte[0], timeByte[1], timeByte[2], timeByte[3],
 						BCC, ETX };

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");
		}

*/
unsigned long accumulator(void) {
	unsigned long startTime, endTime = 0;
	int lastPolltime = millis();
	int signalState;
	int previousState;

	while (1) {
		// poll for card
		getSerialNumber();
		if(!getResponse(readData)) {
			delay(cardTimeout);
			if(!getResponse(readData)) {
				Serial.println("Card not detected.");
				return 0;
			}
