fixing allow to throw proper error incase array is empty