fixed most out of bound errors