Refactoring of sendOrder function