changed argument parser and rewrite some code