refactored javascript to use JSON to build page