performed major tuning to database reading and writing, please modify existing code to match, and implement all new code accordingly