Code refactored: added simple API and command line switches