Improve contact list management code