Remove use of `apply` to be python 3 compatible