refactor this code: `    # Helpful for running tests (e2e)
    if cwd and os.path.isdir(cwd) and os.path.isabs(cwd):
        os.chdir(cwd)
    elif cwd:
        alog.error(f"Path '{cwd}' do not exists")
        return 2
    if not cwd:
        cwd = os.getcwd()
` to new function, how would you handle return 2? knowing that this is inside main() function that returns os status code Wrap the entire output in JSON format.
user