Restructured for consistency and calculated referer url for dev enviroments