refactor three part of database