Pull Request

I found this lovely piece of code, used it and made some modifications and improvements, i hope it gets merged to the main branch.
Some of the items on the TODO list has also been address (partially)