refactor main into a separate module to support cli