adding logic for external referer, correcting condition on referal
adding logic for external referer, correcting condition on referal