refactored app factory and added db factory, changed names for headrs