db: refactorins

sort functions, correct names, join functionality, etc
db: minor refactoring