move some contact-related functions and add util