Added master_host update in the loop

Added master_host update in the loop, returns the right server in case
of multiple servers with same replication depth