Refactored JavaScript to be object oriented.