Refactored

Refactored code. Now it works as a single command line tool.