Reorganize lib/ folder and add main mechanism