Fix cosmetics
Improve logic