ELIF to speed up in mainloop & pseudocode for inv