Modify the logic
Improved performance