In regard to the first sentence, I put a comma before 'when ' because it seemed to be a non-relative clause that defined the preceding part of the sentence. -- The comma is correct, but your reasoning is not. Commas are used set off information which is not defining, which is extra information.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.