fix the failed rendering issue
refactor the insert/update code