refactor __main__

updated stdin/input files handling