In short, whenever the information is essential to identifying the subject, the proper pronoun to use is that. If the information is not essential, or can be set apart with commas, then the pronoun which is more likely to be correct. As is the case with English grammar rules, however, there are going to be some exceptions to this rule. When in doubt, writers can try removing the relative clause and asking themselves if the sentence sounds complete and informative. Some grammar experts suggest silently adding the words "by the way" after which to determine if the information is relevant or irrelevant. If "by the way" seems to fit, then the clause is non-restrictive and should be set off with commas.