public static Consensus reAlign(Alignment layoutMap, double epsilonPrecision, int numOfIterations) {
		Consensus consensus = getConsensus(layoutMap);
		double initialScore = consensus.getConsensusScore();
		boolean shouldContinue = true;
		int iteration = 1;
		int length = layoutMap.keySet().size();
		ArrayList<Integer> keys = new ArrayList<Integer>();
		for (Integer i : layoutMap.keySet()) {
			keys.add(i);
		}
		double minimalScore = initialScore;
		Consensus bestConsensus = consensus;
		
		while(shouldContinue) {
			System.out.println("Iterating...");

			for (int k = 0; k < length; k++) {
				Read sequence = layoutMap.detachFromAlignmentOnIndex(keys.get(k));
				dashFunction(sequence);
				dashFunction(consensus);
				consensus = getConsensus(layoutMap);
				//double deltaConsensusScore =  
				getAlignment(sequence, consensus, sequence.getLength()* epsilonPrecision);

				//score = consensus.consensusScore + deltaConsensusScore + 0.5*getConsensusScoreWithFunction2(sequence, layoutMap);
				
				layoutMap.insertSequenceIntoAlignment(sequence);
				consensus = getConsensus(layoutMap);	
				if (consensus.getConsensusScore() < minimalScore) {
					bestConsensus = consensus;	
					minimalScore = consensus.getConsensusScore();
				}
				//System.out.println(k);
				//System.out.println(bestConsensus.consensusScore);
			}

			if (bestConsensus.getConsensusScore() >= initialScore || iteration == numOfIterations) {
				shouldContinue = false;				
			}
			
			System.out.println("After "+iteration+" iterations score is: "+ bestConsensus.getConsensusScore() +"   previous score : "+initialScore );
			initialScore = bestConsensus.getConsensusScore();
			iteration++;
		}
		
		return bestConsensus;
		
	}