fixed index out of bounds errors