Such a mess of code, but kind of works !