Here I improve code quality and add some functionality...
Needs more commandline options and to be thoroughly tested.