Cleaned up addObject method logic.