Index: BackupChunkHandler.java
===================================================================
--- BackupChunkHandler.java	(revision 1)
+++ BackupChunkHandler.java	(revision 2)
@@ -11,67 +11,104 @@
 import protocols.BackupChunk;
 
 public class BackupChunkHandler implements Runnable {
+	private Peer peer;
+	private Chunk chunk;
+	private final String protocolVersion;
+	private AtomicIntegerArray replication;
+	private int retries = 5;
 
-    private final String protocolVersion;
-    private Peer parentPeer;
-    private Chunk chunk;
-    private AtomicIntegerArray chunkReplication;
-    private int retries = 5;
+	public BackupChunkHandler(BackupChunk backupChunk, Chunk chunk) {
+		this.chunk = chunk;
+		this.peer = backupChunk.getPeer();
+		this.protocolVersion = backupChunk.getVersion();
+		this.replication = peer.getPeerInformation().getChunkReplication(chunk.getFileID());
+	}
 
-    public BackupChunkHandler(BackupChunk backupInitiator, Chunk chunk) {
-        this.chunk = chunk;
-        this.parentPeer = backupInitiator.getPeer();
-        this.protocolVersion = backupInitiator.getVersion();
-        this.chunkReplication = parentPeer.getPeerInformation().getChunkReplication(chunk.getFileID());
-    }
+	BackupChunkHandler(Peer peer, Chunk chunk) {
+		this.chunk = chunk;
+		this.peer = peer;
+		this.protocolVersion = Utils.VERSION;
+		this.replication = null;
+	}
 
-    BackupChunkHandler(Peer parentPeer, Chunk chunk) {
-        this.chunk = chunk;
-        this.parentPeer = parentPeer;
-        this.protocolVersion = Utils.VERSION;
-        this.chunkReplication = null;
-    }
+	@Override
+	public void run() {
+		int waitTime = 1000;
+		Message msg = generatePutChunkMsg(chunk, protocolVersion);
 
-    @Override
-    public void run() {
+		for (int i = 0; i < retries; ++i) {
+			if (isReplicationtheWantedOne() == true) {
+				System.out.println("Achieved desired replication at i=" + i);
+				break;
+			}
+			try {
+				peer.sendMsg(Socket.SocketType.MDB, msg);
+			} catch (IOException e1) {
+				e1.printStackTrace();
+			}
 
-        int waitTime = 1000;
-        Message msg = generatePutChunkMsg(chunk, protocolVersion);
+			try {
+				sleep(waitTime);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
 
-        for (int i = 0; i < retries; ++i) {
-            if (isDesiredReplicationDegree()) {
-            	System.out.println("Achieved desired replication at i=" + i);
-                break;
-            }
+			waitTime *= 2;
+		}
+	}
 
-            try {
-                parentPeer.sendMsg(Socket.SocketType.MDB, msg);
-            } catch (IOException e) {
-            	System.out.println(e.getMessage());
-            }
+	protected boolean isReplicationtheWantedOne() {
+		if(replication != null && replication.get(chunk.getChunkNo()) >= chunk.getReplication())
+			return true;
+		else return false;
+	}
 
-            sleep(waitTime);
-            waitTime *= 2;
-        }
-    }
+	private void sleep(int waitTime) throws InterruptedException {
+		Thread.sleep(waitTime);
+	}
 
-    protected boolean isDesiredReplicationDegree() {
-        return chunkReplication != null && chunkReplication.get(chunk.getChunkNo()) >= chunk.getReplication();
-    }
+	private Message generatePutChunkMsg(Chunk chunk, String protocolVersion) {
+		String[] args = { protocolVersion, Integer.toString(peer.getID()), chunk.getFileID(), Integer.toString(chunk.getChunkNo()), Integer.toString(chunk.getReplication()) };
+		
+		return new Message(Utils.MessageType.PUTCHUNK, args, chunk.getData());
+	}
 
-    private void sleep(int waitTime) {
-        try {
-            Thread.sleep(waitTime);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-    }
+	// Getters and Setters
 
-    private Message generatePutChunkMsg(Chunk chunk, String protocolVersion) {
-        String[] args = { protocolVersion, Integer.toString(parentPeer.getID()), chunk.getFileID(), Integer.toString(chunk.getChunkNo()), Integer.toString(chunk.getReplication())
-        };
+	public Peer getPeer() {
+		return peer;
+	}
 
-        return new Message(Utils.MessageType.PUTCHUNK, args, chunk.getData());
-    }
+	public Chunk getChunk() {
+		return chunk;
+	}
 
+	public String getProtocolVersion() {
+		return protocolVersion;
+	}
+
+	public AtomicIntegerArray getReplication() {
+		return replication;
+	}
+
+	public int getRetries() {
+		return retries;
+	}
+
+	public void setPeer(Peer peer) {
+		this.peer = peer;
+	}
+
+	public void setChunk(Chunk chunk) {
+		this.chunk = chunk;
+	}
+
+	public void setReplication(AtomicIntegerArray replication) {
+		this.replication = replication;
+	}
+
+	public void setRetries(int retries) {
+		this.retries = retries;
+	}
+
 }
