used algorithm to clone