Fixed stack overflow issue.

Also includes more ReplicationTests cleanup.