Doesn't work with new version of spark. I have error "List index out of bounds (-1)"