do refactoring and bugfixing