Fixing out of bounds exception