Several small fixes, including terminal sensing regexp