Refactoring and adding tests
Adding cli tests