Changed cost function
fixed conflicts
fixed build errors