Fixed db duplicated problem and revised update query.