This method is rather complicated and hard to understand. Possible improvements:

  * Add a comment explaining (and showing) what comes out of it
  * Instead of chaining methods, some intermediate variables might make it clearer