First attempt
Got it to function correctly
Tweaked