Refactored and explained. Now ready o use.