Can you extract all this block to a new method? there is too much nesting here