fix and simplify broken logic