move main code to the top
introduce parameter handling and allow setting the log level