rename some functions.
make code much more readable.
remove duplicates.