The code is not difficult to follow and it is hard to see how it could be simplified further. What part(s) are you struggling to understand?

Also you forgot to state what the problem was, i.e. the issue you're trying to solve.