refactor code for create/edit order