It's better to decompose it to deparate functions - it is hard to track such long conditional code blocks