Changed the logic for better results