My Final Code. Faster detecton, bug fixes and so on. Luka.