rewrite source code

improve source code for easy reading.