Mostly refactored SDB