Move most common functions away into a util method