Moved check referer==null to first position in conditional.