First attempt at Cost function