added copying and fixed bug