refactoring and most of core functionality!