Refactor share function