added null check on afterCreatedArray variable