cost function implementatrion added