refactor code for contacts