added new function: truncate_mid