refactoring code and lib to the new struture