Corrected the logic