optimized work with database