solved errors in cost function