Refactored and improved code for easy to use.