refactored google javascript so it is better encapsulated