Wrong cost computation

Did you check this?

If you can send a complete minimal example to debug it, I will have a look soon.