Final Working code

Retroactively adding final, working version of code