ENH: Using integrals and better cost functions