Revert "Revert "Restructuring logic and removing duplicated code""

Reverts nmadhok/OpenInTerminal#11