Added original version of script from David Mavor
Refactored code
Renamed variables