the indentation in this area seems weird, I can't tell what the logic is here.

please ensure there's not a mix of tabs and spaces also.