Refact and remove the pexpect dependency