change logic to make it proper and save time