The o array needs to have up to N * 2 elements.

I'm new to ethereum, but doesn't this array need to have space for 2N elements?

I'm also wondering whether all the "contract.storage[base_index + 1] = 0" stuff is really needed. It seems to be a waste of "gas" to zero out storage that won't ever be read again until it is overwritten.

It's a nit-pick, but as this is example code it would be nice to have it be a good example. :)