Move finding the average intensity to its own method