Fixed code from @cwone
Now is ready to use! Info in description...

Improve the code and fixed logic
dat