refactoring of adding and editing of cost