refactoring continued, fix so many compilation errors, wtf, finally it passed...