moves all core functionality out of the cli code, now usable programmatically as a gem