Fixing object array indexing issue