Added check for array to prevent errors