Why call this function twice? It's also called at L56.
I think this hints at possibility for code factorization (ie. merge the two if-elif-else constructs or something of that type)