Added check for ouf of bounds