fix out of bound errors