Fix bug in .when