Update app.py

Corrected some bugs,optimized the code a bit.