Refactor cli and extract classes