rewrite source code

improve source code for easy reading.
shorten insert sql command.
remove un-necessary variables.