Validate the version
Move logic into its own function

This will make it easier to create unit tests
Add comments
json encode data to be sent to js
Don't expose a variable globally
Only render what we need to