Improve the logic