Refactor Main, DBEntsafter