forgot to open-source an optimization
(code extracted from the gui version source, v1.0, 2013-06-13)