Code optimized

Code optimized. Thanks to Sirius3 (which gave me some tips).
Version is not tested.