The EU is working on a set of “incentives” for African countries to block migrants who do not qualify for asylum closer to their homes. Meanwhile the bloc’s highest court ruled that migrants illegally crossing the internal Shengen borders cannot be jailed.

Plans of a new program that would discourage “irregular” migrants from arriving in Europe from Africa in search of a job rather than asylum was unveiled by the European Union on Tuesday. Countries that are likely to enter the proposed agreement include those that migrants and refugees leave, travel through or stay in on their way to Europe.

“We propose to use a mix of positive and negative incentives to reward those third countries willing to cooperate effectively with us and to ensure that there are consequences for those who do not,” European Commission Vice-President Frans Timmermans told lawmakers in Strasbourg, France.

“We must do the same that we have done on the route through the Aegean also in the southern Mediterranean to find solutions, sustainable solutions,” the former Dutch foreign minister added, referring to EU’s controversial deal with Turkey.

Lawmakers in Strasbourg met the idea with skepticism, with some not sure that Nigeria, Senegal, Mali, Niger and Ethiopia could effectively block migrant flows, and others doubting the EU-countries would be ready to allocate more money on tackling the crisis. Up to €8 billion ($9.1 billion) could be provided to African countries over five years to take back their own citizens and entice others to stay home.

The new initiative was announced just after the European Court of Justice (ECJ) headquartered in Luxembourg said that European Union rules do not allow the incarceration of undocumented migrants for crossing borders within the visa-free Schengen area, unless they have already been subject to deportation procedures. In case of an illegal crossing, Europe’s 2008 Return Directive should be applied which involves sending migrants back to the EU country they came from.

“The return directive prevents a national of a non-EU country who has not yet been subject to the return procedure being imprisoned solely because he or she has entered the territory of a Member State illegally across an internal border of the Schengen area,” the court’s statement said.

An illegal migrant facing deportation has up to 30 days to leave the European country voluntarily. If this doesn’t happen, then the EU is allowed to carry out “forced removal using the least coercive measures possible”.

Migrants can be put in prison but only in the case that the risk of them trying to escape deportation procedures exists, the court specified.

“It is only if there is a risk of the removal being compromised that the Member State may keep the person concerned in detention, the duration of which may not in any case exceed 18 months,” the court said.

The decree doesn’t apply to the UK or Ireland, which while parts of the EU, are not within the Schengen zone. Denmark, a member of the Schengen zone, also doesn’t need to follow the ruling, since it has an opt out from the EU justice policies.

The ruling was prompted by the recent case of a migrant from Ghana, named Selina Affum, who used fake Belgian documents, was caught and detained by French police on the ground of illegally entering France. Affum claimed the arrest was unlawful and the case was transferred from the French Court of Cassation to the European Court of Justice.