Fix out of bounds pointer error