improved the logic
improved the logic