Revert "Revert "Added extremely simple logic to solve the problem. Known problem when you""

This reverts commit 216380c2477fe50a82bf5fc1298cbf889eb41bcb.