fix bug in event sorting code
work around bug in rails where HTTP_REFERER appears not to be set