fixed faulty when/then clause