Improved tests and fix one bug