Global refactoring and some changes of interface.