Cleaned deprecated code usage.
Add tests
clean some code