This whole block is weirdly indented, makes it difficult to follow. The single line `if`'s look like they need to be indented one more tab space.