Refactoring to handle different databases.