better TERM handling, use provided one if it's not unknown