Fixed third task

Fixed mistakes with object allocation and deallocation.
OK, that's right.