considerably simpler logic (and correct)