Refactor shared and non-shared code in to seperate parts of the javascript file and pulled out game in to a class