Some refactoring, added and improving