optimized the code and add the mysql