this if statement is too big and contain too deep nesting. I think it deserve own method or at least move part of responsibility to own method.