Improves pattern to avoid classloader pollution and adds dedicated tests