Bug fix thanks to tests