Refactored code from cli into my_ext