Ugh, that whole code looks like commited halfway through, without even looking at it again. Comments making no sense, variables mutating for no reason...