implemented reg. cost fn