Enhance the logic of the code here