Prepared db to have JSON functions + bugfixes

Added a sort_by method to tools
Changed 'config' to 'cfg'