Fixing "when" clause