Modified to handle also different type of contatcs. Tested on subject17