Changing the javascript to hold fully object oriented paatern