First attempt
With comments, cleaned the code up a bit and a better understanding