private Data[] executeCommandsOnNodes(int commandType, final Command[] commands) throws InterruptedException{
		final int maxCounterMsg;
		if(commandType == Command.INSERT_TABLE){
			maxCounterMsg = 2;
		}else{
			maxCounterMsg = numberOfNodes;
		}
		final CountDownLatch latch = new CountDownLatch(maxCounterMsg);
		final Data[] result = new Data[numberOfNodes];
		
		for(int i=0; i!=numberOfNodes; ++i){
			final int index = i;
			
			if(commands[index] == null)	continue;
			
			Thread t = new Thread(new Runnable() {
				@Override
				public void run() {
					
					++counterMsgSent;
					if(counterMsgSent == maxCounterMsg){
						console.append("Command has been sent to " + counterMsgSent + " of " + maxCounterMsg + " nodes\n");
						counterMsgSent = 0;
					}
					
					try {
						
						// output to the console
						if(!nodeNames[index].equals(myName)){
							if(nodesSocket[index] != null){
								// send to the node
								nodesOut[index].writeObject(Message.NODE);
								nodesOut[index].writeObject(commands[index]);
						
								// receive from the node
								result[index] = (Data)nodesIn[index].readObject();
							}
						}else{
							result[index] = dataBase.execute(commands[index]);
							
						}
					} catch (IOException e) {
						console.append("6. " + e.getMessage() + '\n');
						nodesSocket[index] = null;
						nodesOut[index] = null;
						nodesIn[index] = null;
					} catch (ClassNotFoundException e) {
						console.append("7. "+ e.getMessage() + '\n');
					}finally{
						latch.countDown();
					}
					
					++counterMsgReceived;
					if(counterMsgReceived == maxCounterMsg){
						console.append("Command has been recieved from " + counterMsgReceived + " of " + maxCounterMsg + " nodes\n");
						counterMsgReceived = 0;
					}
				}
			});
			
			t.start();
			
		}
		
		latch.await();
		
		return result;
	}