fixed bug out of bounds