Yep, it could be divided. I also do not like so many levels of if statements.
But looking at code - only lines 75-82 deserves to rip out from for body... Or - maybe rip out all try internal part would be good?