Improved coda retrieving algorithm.

In particular it doesn't use ifs.