modifications to R functions for BFF case study- now works