Implement truncate function