private void addReplaceFile(COMMAND cmd, boolean isLastMessage, String filename, int dataLength, byte[][] data) {
		try {
			File file = null;
			
			// Open the file to write
			if(cmd.equals(COMMAND.A)) {
				String fileOutputLocation = Server.SERVERDIRECTORIES[0].concat("/" + filename);
				file = new File(fileOutputLocation);
				if(file.exists()) {
					// file modified --> delete the signatures
					deleteSigns(filename);
				}
			} else if(cmd.equals(COMMAND.U)) {
				String fileOutputLocation = Server.SERVERDIRECTORIES[1].concat("/" + new File(filename).getName());
				file = new File(fileOutputLocation);
			} else if (cmd.equals(COMMAND.V)){
				String[] parts = filename.split("_");
				
				
				String fileOutputLocation = Server.SERVERDIRECTORIES[2].concat("/" + parts[0]);
				File folder = new File(fileOutputLocation);
				folder.mkdir();
				System.out.println(folder.getName());
				file = new File("./ServerSignatures/" + folder.getName() + "/" + filename);
			} else {
				throw new IllegalArgumentException("ERROR: Message command in addReplaceFile call is not '-u', '-a' or '-v'");
			}
			System.out.println(">>>Server: Message received with command = '" + cmd + "' for file '" + filename + "'");
			
			//########################### Assuming all files are read/write and can be written over 
			FileOutputStream fos = new FileOutputStream(file);
			
			// Write the data to file
			fos.write(data[0], 0, dataLength);
			
			// Listen for any other messages
			if(!isLastMessage) {
				boolean messageEnd = isLastMessage;
				Message msg = null;
				// Until we've received the last message
				while(!messageEnd) {
					// Cast & store the message, then write message data to file
					msg = (Message) objectFromClient.readObject();
					messageEnd = msg.isLastMessage();
					fos.write(msg.getData()[0], 0, msg.getDataLength());
				}
			}
			
			// Send acknowledgement to the client
			sendAck(COMMAND.C, true);
			
			// Close and print method success
			fos.close();
			System.out.println("Server: Client file successfully written to Server folder");
		} catch(IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			System.out.println("Error reading extra message in addReplaceFile");
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}