Code simplify and database optimization