Reorganize code

Code reorganized
New function
Full test on 1.3 and 1.1.8