Some code improvements:
  - using Printf
  - add comments
  - change function names
  - ...