added array bounds checking to input