Clean up code and add tests for helper functions
Improve CLI commands