huge code refactoring
some dewarning