restructured js and request handling