Added bounds checking