Fixed copy and assign bugs and added tests.