rewrite source code

improve source code for easy reading.
shorten insert/update.
remove unwanted variables.