Changed everything from PHP to Javascript