First implementation of clone function