Add support for optimizing an index

Very happy to report this is the only change I've needed so far! :)

Let me know what else you'd like to see to get this released.