Refactoring functions coods