[FIX] PEP8

This is far too indented, recommend factoring into dedicated functions or combine ifs with and