Database api introduced (with litle code refactoring).