Refactor some cost/err and change definition of some costs