fixing bugs with arrays