Add indexes, refactor db classes