Global refactoring: new library structure, some bug fixed, realization improvement