Fixed a couple of bugs in AddObject method.