Friendliness to other databases

This branch attempts to refactor the code a little to be friendlier to extensions.