Added clone function, bug fixing