change to cond instead of doing two when's for each loop