fixed an error involving sapply