Added Matthias's suggestions for making the coverage function faster