Doc and reorganize code