Big refactoring and some patches for improve detection
Add ability to choose main frame
Refactoring