Are you really using lastObject as an index or length, because if check if lastObject > totalObjects, it makes me assume it is a length