refactored as Object Oriented Javascript