fixed errors of going out of bounds