Added count to replace_source function so that first N instances can be replaced or all instances