cleaned referrer, fixed value replacement to work with melted data frame, removed unnecessary packages, moved functions to the top