final review

Fix a small issue with database. The codes is a mess though.