Refactoring and add new function