ensure only last occurrence of pkg name is replaced