Make trim and count generic functions
Return exact count for threads as well