1. stablized database integration. 2. added debug print mechanism and extra prints. 3. fixed some bugs.