added truncate utility function