code refactoring3: made changes to cost function
code refactoring3: made changes to cost functions