Refactored and added CLI functionality