Data base and cost functions