write progress bar straight to stdout instead of using a buffer for
speed; improve readability and added some more comments