add copy constructor and fix bugs