Reorganize lib code