finish implementing and submitting cost function