introduced long options; improved structure of code by splitting it into functions