fixed error involving sapply