Introduce new tests and many code improvments, compatible with 4.0