Fix #381: Better API for preoptimizer and optimizer.

The API is now focused on the content needed for the
optimizers to do their job, rather than on a file system-like
architecture.