Refactor __init__ from db